#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 20 17:44:37 2024

@author: Nicholas Drachman
"""

import sys
# Insert path to advMSplot.py below
# sys.path.append('INSERT PATH HERE')

from advMSplot import *

import pandas as pd




path = 'Fig 3/MAY 9 2024 22-16.cdf'

scan_range1 = (100,3000)
scan_range2 = (3700,6000)


bins1, histogram1, num_scans1 = process_mass_spectrum(path, 0, [scan_range1], 0.125)
bins2, histogram2, num_scans2 = process_mass_spectrum(path, 0, [scan_range2], 0.125)

N = 35

sigma = 15  # Standard deviation of the Gaussian
kernel_size = int(6*sigma + 1)  # Kernel size is typically chosen as 6*sigma + 1

# Smooth the array using the Gaussian kernel in a single line
bins_smooth1 = np.convolve(bins1, np.exp(-0.5 * (np.linspace(-3*sigma, 3*sigma, kernel_size) / sigma)**2) / (sigma * np.sqrt(2 * np.pi)), mode='same')
hist_smooth1 = np.convolve(histogram1, np.exp(-0.5 * (np.linspace(-3*sigma, 3*sigma, kernel_size) / sigma)**2) / (sigma * np.sqrt(2 * np.pi)), mode='same')

bins_smooth2 = np.convolve(bins2, np.exp(-0.5 * (np.linspace(-3*sigma, 3*sigma, kernel_size) / sigma)**2) / (sigma * np.sqrt(2 * np.pi)), mode='same')
hist_smooth2 = np.convolve(histogram2, np.exp(-0.5 * (np.linspace(-3*sigma, 3*sigma, kernel_size) / sigma)**2) / (sigma * np.sqrt(2 * np.pi)), mode='same')



fig, ax = plt.subplots(figsize = [3.5, 2.75])

ax.plot(bins_smooth1,hist_smooth1/np.max(hist_smooth1[500:]), '--', label = 't = 0 min', zorder= 10)
ax.plot(bins_smooth2,hist_smooth2/np.max(hist_smooth2[500:]), label = 't = 45 min')
ax.set_xlim(200,700)
ax.set_ylim(0, 1.1)
ax.set_xlabel('m/z')
ax.set_ylabel('Norm. intensity')
ax.tick_params(direction = 'in')
ax.legend()
plt.tight_layout()